package org.gpp.proj1.demo.map.sky;

import java.io.File;
import java.net.MalformedURLException;
import java.util.Properties;

import org.gpp.proj1.util.PropertyLoader;

import com.jme.image.Texture;
import com.jme.scene.Skybox;
import com.jme.util.TextureManager;

/**
 * 
 * @author Gustavo de Farias
 */
public class PreparedSkyBox {

	private Skybox box;
	
	/**
	 * @param skyFile
	 */
	public PreparedSkyBox(String skyFile) {
		
		Properties p = PropertyLoader.loadProperties(skyFile);
		
		String name = p.getProperty("name");
		float x = Float.parseFloat(p.getProperty("x"));
		float y = Float.parseFloat(p.getProperty("y"));
		float z = Float.parseFloat(p.getProperty("z"));
		
		Texture up = null;
		Texture down = null;
		Texture north = null;
		Texture south = null;
		Texture east = null;
		Texture west = null;
		try {
			up = TextureManager.loadTexture(new File(p.getProperty("up")).toURL(), Texture.MM_LINEAR, Texture.FM_LINEAR);
			down = TextureManager.loadTexture(new File(p.getProperty("down")).toURL(), Texture.MM_LINEAR, Texture.FM_LINEAR);
			north = TextureManager.loadTexture(new File(p.getProperty("north")).toURL(), Texture.MM_LINEAR, Texture.FM_LINEAR);
			south = TextureManager.loadTexture(new File(p.getProperty("south")).toURL(), Texture.MM_LINEAR, Texture.FM_LINEAR);
			east = TextureManager.loadTexture(new File(p.getProperty("east")).toURL(), Texture.MM_LINEAR, Texture.FM_LINEAR);
			west = TextureManager.loadTexture(new File(p.getProperty("west")).toURL(), Texture.MM_LINEAR, Texture.FM_LINEAR);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
			
		this.box = new Skybox(name, x, y, z);
		this.box.setTexture(Skybox.UP, up);
		this.box.setTexture(Skybox.DOWN, down);
		this.box.setTexture(Skybox.NORTH, north);
		this.box.setTexture(Skybox.SOUTH, south);
		this.box.setTexture(Skybox.EAST, east);
		this.box.setTexture(Skybox.WEST, west);
		this.box.preloadTextures();
	}
	
	/**
	 * @return
	 */
	public Skybox getSkyNode() {
		return this.box;
	}
}